home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / bin / showexternal.z / showexternal
Encoding:
Text File  |  1997-01-22  |  6.1 KB  |  247 lines

  1. #!/bin/csh -fb
  2. # (The "-fb" might need to be changed to "-f" on some systems)
  3. #
  4. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  5. # Permission to use, copy, modify, and distribute this material 
  6. # for any purpose and without fee is hereby granted, provided 
  7. # that the above copyright notice and this permission notice 
  8. # appear in all copies, and that the name of Bellcore not be 
  9. # used in advertising or publicity pertaining to this 
  10. # material without the specific, prior written permission 
  11. # of an authorized representative of Bellcore.  BELLCORE 
  12. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  13. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  14. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  15.  
  16. onintr cleanup
  17. if (! $?METAMAIL_TMPDIR) then
  18.     set METAMAIL_TMPDIR=/tmp
  19. endif
  20. if (! $?FTP) then
  21.     set FTP=ftp
  22. endif
  23.  
  24. if ($#argv <3) then
  25.     echo "Usage: showexternal body-file access-type name [site [directory [mode [server]]]]"
  26.     exit -1
  27. endif
  28. set bodyfile=$1
  29. set atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  30. set name=$3
  31. if ($#argv > 3) then
  32.     set site=$4
  33. else 
  34.     set site=""
  35. endif
  36. if ($#argv > 4) then
  37.     set dir=$5
  38. else
  39.     set dir=""
  40. endif
  41. if ($#argv > 5) then
  42.     set mode=$6
  43. else
  44.     set mode=""
  45. endif
  46. if ($#argv > 6) then
  47.     set server=$7
  48. else
  49.     set server=""
  50. endif
  51.  
  52. if ("$server" == "" && $atype == "mail-server") then
  53. # Backward compatibility with some broken stuff
  54.     set server=${name}@${site}
  55.     echo WARNING -- old style mailserver syntax, using server $server
  56. endif
  57.  
  58. set ctype="`grep -i content-type: $bodyfile | sed -e 's/............: //'`"
  59. if ("$ctype" == "") set ctype="text/plain"
  60. set cenc=`grep -i content-transfer-encoding: $bodyfile | sed -e 's/.........................: //'`
  61. set username=""
  62. set pass=""
  63. set TMPDIR=${METAMAIL_TMPDIR}/Xternal.$$
  64. mkdir $TMPDIR
  65. pushd $TMPDIR
  66. set NEWNAME="mm.ext.$$"
  67. set NEEDSCONFIRMATION=1
  68. switch ("$atype")
  69.     case anon-ftp:
  70.     echo "This mail message contains a POINTER (reference) to data that is "
  71.     echo not included in the message itself.  Rather, the data can be retrieved 
  72.     echo automatically using  anonymous FTP to a site on the network.
  73.     breaksw
  74.     case ftp:
  75.     echo "This mail message contains a POINTER (reference) to data that is "
  76.     echo not included in the message itself.  Rather, the data can be retrieved 
  77.     echo automatically using  the FTP protocol to a site on the network.
  78.     breaksw
  79.     case mail-server:  
  80.     cat > ${METAMAIL_TMPDIR}/X.junk.$$ <<!
  81. This mail message contains a POINTER (reference) to data that is 
  82. not included in the message itself.  Rather, the data can be retrieved 
  83. by sending a special mail message to a mail server on the network.
  84. However, doing this automatically is slightly dangerous, because  someone
  85. might be using this mechanism to cause YOU to send obnoxious mail.
  86. For that reason, the mail message that WOULD be sent is being shown to you
  87. first for your approval.
  88.  
  89. This is the message that will be sent if you choose to go ahead and
  90. retreive the external data:
  91.  
  92. Subject: Automated Mail Server Request
  93. To: ${server}
  94.  
  95. !
  96.     sed -e 1,/^\$/d < $bodyfile >> ${METAMAIL_TMPDIR}/X.junk.$$
  97.     more ${METAMAIL_TMPDIR}/X.junk.$$
  98.     rm ${METAMAIL_TMPDIR}/X.junk.$$
  99.     breaksw
  100.     default:
  101.     # IGNORE ALL THE OTHERS -- AUTOMATIC FOR LOCAL-FILE, AFS.
  102.     set NEEDSCONFIRMATION=0
  103. endsw
  104.  
  105. if ($NEEDSCONFIRMATION) then
  106.     echo ""
  107.     echo -n "Do you want to proceed with retrieving the external data [y] ? "
  108.     set ANS=$<
  109.     if ("$ANS" =~ n* ||  "$ANS" =~ N* ) then
  110.         cd ${METAMAIL_TMPDIR}
  111.         rm -rf $TMPDIR
  112.         exit 0
  113.     endif
  114. endif
  115.  
  116. switch ("$atype")
  117.     case anon-ftp:
  118.     set username=anonymous
  119.     set pass=`whoami`@`hostname`
  120.     # DROP THROUGH
  121.     case ftp:
  122.     if ("$site" == "") then
  123.         echo -n "Site for ftp access: "
  124.         set site=$<
  125.     endif
  126.     if ("$username" == "") then
  127.         echo -n "User name at site ${site}: "
  128.         set username=$<
  129.     endif
  130.     if ("$pass" == "") then
  131.         echo -n "Password for user $username at site ${site}: "
  132.         stty -echo
  133.         set pass=$<
  134.         stty echo
  135.         echo ""
  136.     endif
  137.     if ("$dir" == "") then
  138.         set DIRCMD=""
  139.     else
  140.         set DIRCMD="cd $dir"
  141.     endif
  142.     if ("$mode" == "") then
  143.         set MODECMD=""
  144.     else
  145.         set MODECMD="type $mode"
  146.     endif
  147.     echo OBTAINING MESSAGE BODY USING FTP
  148.     echo SITE: $site USER $username
  149.     $FTP -n <<!
  150. open $site
  151. user $username $pass
  152. $DIRCMD
  153. $MODECMD
  154. get $name $NEWNAME
  155. quit
  156. !
  157.     if (! -e $NEWNAME) then
  158.         echo FTP failed.
  159.         cd ${METAMAIL_TMPDIR}
  160.         rm -rf $TMPDIR
  161.         exit -1
  162.     endif
  163.     breaksw
  164.     case afs:
  165.     case local-file:
  166.     if (! -e $name) then
  167.         echo local file not found
  168.         cd ${METAMAIL_TMPDIR}
  169.         rm -rf $TMPDIR
  170.         exit -1
  171.     endif
  172.         set NEWNAME=$name
  173.     echo GETTING BODY FROM FILE NAMED: $NEWNAME
  174.     breaksw
  175.     case mail-server:  # A very special case
  176.     if ("$bodyfile" == "") then
  177.         echo mail-server access-type requires a body file
  178.         cd ${METAMAIL_TMPDIR}
  179.         rm -rf $TMPDIR
  180.         exit -1
  181.     endif
  182.     echo Subject: Automated Mail Server Request > $NEWNAME
  183.     echo To: ${server} >> $NEWNAME
  184.     echo "" >> $NEWNAME
  185.     sed -e 1,/^\$/d < $bodyfile >> $NEWNAME
  186.     echo "" >> $NEWNAME
  187.     /usr/lib/sendmail -t  < $NEWNAME
  188.     if ($status) then
  189.         echo sendmail failed
  190.         cd ${METAMAIL_TMPDIR}
  191.         rm -rf $TMPDIR
  192.         exit -1
  193.     endif
  194.     cd ${METAMAIL_TMPDIR}
  195.     rm -rf $TMPDIR
  196.     echo Your $ctype data has been requested from a mail server.
  197.     exit 0
  198.     default:
  199.     echo UNRECOGNIZED ACCESS-TYPE
  200.     cd ${METAMAIL_TMPDIR}
  201.     rm -rf $TMPDIR
  202.     exit -1
  203. endsw
  204. if ($cenc == base64) then
  205.     mimencode -u -b < $NEWNAME > OUT
  206.     mv OUT $NEWNAME
  207. else if ($cenc == quoted-printable) then
  208.     mimencode -u -q < $NEWNAME > OUT
  209.     mv OUT $NEWNAME
  210. endif
  211.  
  212. popd
  213. if ($atype == "local-file") then
  214.     metamail -p  -b -c "$ctype" $NEWNAME
  215. else
  216.     metamail -p -b -c "$ctype" $TMPDIR/$NEWNAME
  217. endif
  218.  
  219. if ($status) then
  220.     echo metamail failed
  221.     cd ${METAMAIL_TMPDIR}
  222.     rm -rf $TMPDIR
  223.     exit -1
  224. endif
  225.  
  226. if ($NEWNAME != $name) then
  227.     echo ""
  228.     echo The data just displayed is stored in the file $TMPDIR/$NEWNAME
  229.     echo "Do you want to delete it?"
  230.     rm -i $TMPDIR/$NEWNAME
  231. endif
  232.  
  233. if (! -e ${TMPDIR}/${NEWNAME}) then
  234.     cd ${METAMAIL_TMPDIR}
  235.     rmdir $TMPDIR
  236. endif
  237. exit 0
  238.  
  239. cleanup:
  240. cd ${METAMAIL_TMPDIR}
  241. if (-e $TMPDIR) then    
  242.     rmdir $TMPDIR
  243. endif
  244. exit -1
  245.